package com.xhl.spring.module.other;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author CazCen
 * @Date 2021/12/1 22:44
 */
@Component
@Slf4j
public class XhlInitializingBean implements InitializingBean {

    /**
     * 传统的方式是 new stringBuffer()
     * StringBuffer 不能通过Spring装配初始化，但又想在 XhlInitializingBean 装配的时候初始化 StringBuffer
     * 通过实现 InitializingBean 来初始化
     */
    private StringBuffer stringBuffer;

    @Override
    public void afterPropertiesSet() throws Exception {
        stringBuffer = new StringBuffer(0);
        log.info("XhlInitializingBean 初始化完成，执行 afterPropertiesSet 完成 StringBuffer 初始化");
    }

    @PostConstruct
    public void doPostConstruct(){
        log.info("我是 PostConstruct，在 XhlInitializingBean 初始化完成之后执行 !!!");
    }
}
